
/**
  ******************************************************************************
  * Copyright 2021 The Microbee Authors. All Rights Reserved.
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  * 
  * http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * 
  * @file       sim_battery.h
  * @author     baiyang
  * @date       2022-11-28
  ******************************************************************************
  */

#pragma once

#ifdef __cplusplus
extern "C"{
#endif

/*----------------------------------include-----------------------------------*/
#include <common/gp_math/gp_mathlib.h>
/*-----------------------------------macro------------------------------------*/

/*----------------------------------typedef-----------------------------------*/
typedef struct sim_battery* sim_battery_t;
typedef const struct sim_battery* sim_battery_const_t;

struct sim_battery {
    float capacity_Ah;
    float resistance;
    float max_voltage;
    float voltage_set;
    float remaining_Ah;
    uint64_t last_us;

    // 10Hz filter for battery voltage
    LowPassFilt voltage_filter;
};
/*----------------------------------variable----------------------------------*/

/*-------------------------------------os-------------------------------------*/

/*----------------------------------function----------------------------------*/
void sim_battery_setup(sim_battery_t battery, float _capacity_Ah, float _resistance, float _max_voltage);
void sim_battery_init_voltage(sim_battery_t battery, float voltage);
void sim_battery_set_current(sim_battery_t battery, float current);

static inline float sim_battery_get_voltage(sim_battery_const_t battery) { return lpf_get_output(&battery->voltage_filter); }
/*------------------------------------test------------------------------------*/

#ifdef __cplusplus
}
#endif



